﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UFSSWebApp
{
    public partial class register : System.Web.UI.Page
    {
        UFSSservicereference.UserCreds uc = new UFSSservicereference.UserCreds();
        UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSservicereference.UFSSserviceSoapClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (txtPassword1.Text.Equals(txtPassword2.Text) && txtEmail1.Text.Equals(txtEmail2.Text))
            {
                if (ussc.CreateUser(txtFirstname.Text, txtLastname.Text, txtUsername.Text, txtPassword1.Text, txtEmail1.Text))
                {
                    uc.Username = txtUsername.Text;
                    uc.Password = txtPassword1.Text;

                    ussc.LoginUser(ref uc);

                    Session.Add("usercreds", uc);
                    Session.Add("Username", uc.Username);
                    Session.Timeout = 1440;
                    Response.Redirect("~/home.aspx");
                }
                else
                    lblError.Visible = true;
            }
        }
    }
}